import pgzrun

IMG_SIZE = 160

WIDTH = IMG_SIZE * 3
HEIGHT = IMG_SIZE * 3

images = {}

for i in range(1, 10):
    images[i] = Actor(str(i))

ROWS = 3
COLS = 3

board = [[0 for r in range(ROWS)] for c in range(COLS)]

r = 0
c = COLS // 2
iter = 1
board[r][c] = iter
iter += 1

while iter <= ROWS * COLS:
    nr = r
    nc = c
    nr -= 1
    nc -= 1
    if nr < 0:
        nr = ROWS - 1

    if nc < 0:
        nc = COLS - 1

    if board[nr][nc] == 0:
        r = nr
        c = nc
        board[r][c] = iter
    else:
        r += 1
        board[r][c] = iter
    
    iter += 1

for r in range(ROWS):
    print(board[r])

def update():
    pass

def draw():
    for r in range(ROWS):
        for c in range(COLS):
            num = board[r][c]
            img = images[num]
            x = c * IMG_SIZE + IMG_SIZE // 2
            y = r * IMG_SIZE + IMG_SIZE // 2
            img.pos = x, y
            img.draw()

pgzrun.go()